home *** CD-ROM | disk | FTP | other *** search
- const gDap_ConsoleService =
- Components.
- classes['@mozilla.org/consoleservice;1'].
- getService(Components.interfaces.nsIConsoleService);
- var bLog = false;
-
-
- function IsLog()
- {
- try
- {
- var obj = Components.classes["@speedbit.com/dapfirefox/dapcomponent;1"].createInstance();
- obj = obj.QueryInterface(Components.interfaces.IDAPComponent);
- return obj.IsWriteLog();
-
- }
- catch(ex)
- {
-
- }
- return false;
- }
-
- function LOG(aMessage)
- {
- if( bLog == false )
- bLog = IsLog();
-
- if( bLog == false )
- return;
-
- gDap_ConsoleService.logStringMessage('DAP Service: ' + aMessage);
- }
-
- const URI_DATA_LOCALE = "chrome://dapff/locale/dapff.properties";
- const EXTENSION_ID = "{F17C1572-C9EC-4e5c-A542-D05CBB5C5A08}";
- ///////////////////////////////////////////////////////////////////////////////////////////////////
-
- function DAPService()
- {
- this._init();
- }
-
-
- DAPService.prototype =
- {
-
- bRegular:0,
- bMinIntegration:0,
- // nsISupports ============================================================
-
- //-------------------------------------------------------------------------
- QueryInterface: function(iid)
- {
- if (iid.equals(Components.interfaces.nsIURIContentListener) ||
- iid.equals(Components.interfaces.nsISupportsWeakReference) ||
- iid.equals(Components.interfaces.nsIFactory) ||
- iid.equals(Components.interfaces.nsISupports) ||
- iid.equals(Components.interfaces.nsIObserver ) )
- {
- return this;
- }
- throw Components.results.NS_ERROR_NO_INTERFACE;
- },
-
-
- // nsIFactory =============================================================
- createInstance: function(outer, iid)
- {
- LOG("Create instans");
- if (null != outer)
- {
- throw Components.results.NS_ERROR_NO_AGGREGATION;
- }
- return this.QueryInterface(iid);
- },
- shoudtrig : function ()
- {
- // user choose in dialog regular speed
- if( this.isRegular() )
- return false;
- // user unintegrate with browser , only context menu
- if( this.isMinIntegration() )
- return false;
-
- return false;
-
- /*try
- {
- var obj = this.getDAPComponent();
- if( !obj )
- {
- LOG("DAP not exist");
- return false;
- }
- // problem run dap
- if( !this._runDAP() )
- return false;
-
- if( obj.IsAccelerate() )
- return true;
-
- this.setRegularDownload(true);
- return false;
- }
- catch(ex)
- {
- LOG(ex);
- }*/
-
- },
- setRegularDownload : function (value)
- {
- LOG("setRegularDownload");
- this.bRegular = value;
- },
- isRegular : function ()
- {
- LOG("isRegular");
- return this.bRegular;
- },
- isMinIntegration : function()
- {
- LOG("min Integration");
- return this.bMinIntegration ;
- },
- unregister :function ()
- {
- const osvr=Components.classes['@mozilla.org/observer-service;1'].getService(
- Components.interfaces.nsIObserverService);
- osvr.removeObserver(this,"xpcom-shutdown");
- osvr.removeObserver(this,"em-action-requested",false);
- },
- getDAPComponent : function()
- {
- return Components.classes["@speedbit.com/dapfirefox/dapcomponent;1"].createInstance().
- QueryInterface(Components.interfaces.IDAPComponent);
- },
- checkDAPIntegr: function()
- {
- const nsIWindowsRegKey = Components.interfaces.nsIWindowsRegKey;
- var key = Components.classes["@mozilla.org/windows-registry-key;1"]
- .createInstance(nsIWindowsRegKey);
-
- var path = "Software\\SpeedBit\\Download Accelerator";
- var root = nsIWindowsRegKey.ROOT_KEY_CURRENT_USER;
- try
- {
- key.open(root, path, nsIWindowsRegKey.ACCESS_READ);
- this.bMinIntegration = key.readIntValue("FFMinIntegration");
- LOG(this.bMinIntegration);
- } catch(e)
- {
- LOG(e);
- }
- key.close();
-
- },
- _setToDap : function( value )
- {
- LOG("Send to DAP");
- LOG(value);
- try
- {
- var obj = this.getDAPComponent();
- if( obj )
- obj.SetExtentionState(value);
- }
- catch(ex)
- {
- LOG(ex);
- }
-
- },
- observe: function(subject, topic, data)
- {
- LOG("observe");
- switch(topic)
- {
- case "xpcom-shutdown":
- this.unregister();
- break;
- case "em-action-requested" :
- if( (subject instanceof Components.interfaces.nsIUpdateItem)
- && subject.id==EXTENSION_ID )
- {
- if( data == "item-disabled" )
- this._setToDap(true);
- if( data == "item-cancel-action" )
- this._setToDap(false);
- if( data == "item-enabled" )
- {
- this._setToDap(false);
- LOG("enable");
- }
-
- break;
- }
- }
- },
-
-
-
- // nsIURIContentListener ==================================================
-
- //-------------------------------------------------------------------------
- canHandleContent: function(contentType, isContentPreferred, desiredContentType)
- {
-
- return this.shoudtrig();
- },
-
-
- //-------------------------------------------------------------------------
- doContent: function(contentType, isContentPreferred, request, contentHandler)
- {
- LOG(request.name);
- try
- {
- request.QueryInterface(Components.interfaces.nsIChannel);
- const uri = request.URI;
-
- var obj = this.getDAPComponent();
-
- if( obj && obj.IsShoudTrigger(request.name) )
- obj.SendToDAP(request.name,uri.host,"","",window.navigator.userAgent);
-
- // cancel request
- contentHandler.value=null;
- request.cancel(Components.results.NS_BINDING_ABORTED);
-
- }
- catch(ex)
- {
- LOG(ex);
- }
-
- return true;
- },
-
-
- //-------------------------------------------------------------------------
- isPreferred: function(contentType, desiredContentType)
- {
- return this.shoudtrig();
- },
-
-
- //-------------------------------------------------------------------------
- onStartURIOpen: function(uri)
- {
- // false == abort load
- return false;
- },
-
-
- // Our Stuff ==============================================================
-
- //-------------------------------------------------------------------------
- get wrappedJSObject() { LOG("wrappedJSObject"); return this; },
- _checkDAP : function()
- {
-
- var window = Components.classes['@mozilla.org/appshell/window-mediator;1']
- .getService(Components.interfaces.nsIWindowMediator).getMostRecentWindow (null);
- if( !window )
- {
- LOG("Window is null");
- return ;
- }
-
- const nsIWindowsRegKey = Components.interfaces.nsIWindowsRegKey;
- var key = Components.classes["@mozilla.org/windows-registry-key;1"]
- .createInstance(nsIWindowsRegKey);
-
- var path = "Software\\SpeedBit\\Download Accelerator";
- var root = nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE;
- var appPath;
-
- try
- {
- key.open(root,path,nsIWindowsRegKey.ACCESS_READ);
- appPath = key.readStringValue("EXELOCATION");
- key.close();
-
-
- var exeFile = Components.classes["@mozilla.org/file/local;1"] .createInstance(Components.interfaces.nsILocalFile);
-
- exeFile.initWithPath(appPath);
- if ( !exeFile.exists() )
- {
- LOG("File not exists");
- window.openDialog("chrome://dapff/content/confirm.xul","_blank","chrome,centerscreen,resizable=no");
- return false;
- }
-
-
-
- }
- catch(ex)
- {
- LOG(ex);
- if( !appPath )
- {
- window.openDialog("chrome://dapff/content/confirm.xul","_blank","chrome,centerscreen,resizable=no");
- return false;
- }
-
- }
- return true;
- },
- getDAPExeLocation : function()
- {
-
- const nsIWindowsRegKey = Components.interfaces.nsIWindowsRegKey;
- var key = Components.classes["@mozilla.org/windows-registry-key;1"]
- .createInstance(nsIWindowsRegKey);
-
- var path = "Software\\SpeedBit\\Download Accelerator";
- var root = nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE;
- var appPath;
- try
- {
- key.open(root,path,nsIWindowsRegKey.ACCESS_READ);
- appPath = key.readStringValue("EXELOCATION");
- key.close();
-
- }
- catch(ex)
- {
- LOG("get Dap exelocation");
- LOG(ex);
- return null;
- }
- return appPath;
-
- },
- showalert : function()
- {
- if( this.isRegular() )
- return;
-
- var prompt = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
- .getService(Components.interfaces.nsIPromptService);
- LOG("Prompt");
- var localeService = Components.classes["@mozilla.org/intl/nslocaleservice;1"].
- getService(Components.interfaces.nsILocaleService);
- var appLocale = localeService.getApplicationLocale( );
-
- var sbs = Components.classes["@mozilla.org/intl/stringbundle;1"].
- getService(Components.interfaces.nsIStringBundleService);
-
- var Bundle = sbs.createBundle(URI_DATA_LOCALE);
- if( !Bundle )
- {
- LOG("Bundle is null");
- return;
- }
- var Message = Bundle.GetStringFromName("dapff.text-message");
-
- prompt.alert(null,"DAP",Message);
- this.setRegularDownload(true);
-
- },
- _runDAP : function()
- {
- LOG("RUN DAP");
-
-
- var appPath = this.getDAPExeLocation();
-
- if( !appPath )
- {
- this.showalert();
- return false;
- }
-
-
- try
- {
-
- var exeFile = Components.classes["@mozilla.org/file/local;1"] .createInstance(Components.interfaces.nsILocalFile);
-
- exeFile.initWithPath(appPath);
- if ( !exeFile.exists() )
- {
- this.showalert();
- return false;
- }
- //var app = Components.classes["@mozilla.org/process/util;1"]
- // .createInstance(Components.interfaces.nsIProcess);
-
- //app.init(exeFile);
- //app.run(false," /HIDE /ID=DAPFF",0);
-
- }
- catch(ex)
- {
- LOG("Catch runDAP");
- LOG(ex);
-
- this.showalert();
- return false;
-
- }
- return true;
- },
- //-------------------------------------------------------------------------
- _init: function()
- {
-
- // Register this as content listener
- Components.classes["@mozilla.org/uriloader;1"]
- .getService(Components.interfaces.nsIURILoader)
- .registerContentListener(this);
- const osvr=Components.classes['@mozilla.org/observer-service;1'].getService(
- Components.interfaces.nsIObserverService);
- osvr.addObserver(this,"xpcom-shutdown",false);
-
- osvr.addObserver(this,"em-action-requested",false);
-
- this.setlocalstringToComponent();
- this.checkDAPIntegr();
- this._setToDap(false);
- },
- setlocalstringToComponent : function()
- {
- LOG("setlocalstringToComponent ");
- try
- {
-
- var localeService = Components.classes["@mozilla.org/intl/nslocaleservice;1"].
- getService(Components.interfaces.nsILocaleService);
- var appLocale = localeService.getApplicationLocale( );
-
- var sbs = Components.classes["@mozilla.org/intl/stringbundle;1"].
- getService(Components.interfaces.nsIStringBundleService);
-
- var Bundle = sbs.createBundle(URI_DATA_LOCALE);
- if( !Bundle )
- {
- LOG("Bundle is null");
- return;
- }
- var TotalString ;
-
- var title = Bundle.GetStringFromName("dapff.title-choose-dlg");
- TotalString = title + '╢';
- title = Bundle.GetStringFromName("dapff.text-choose-dlg");
- TotalString = TotalString + title + '╢';
- title = Bundle.GetStringFromName("dapff.button-regular");
- TotalString = TotalString + title + '╢';
- title = Bundle.GetStringFromName("dapff.button-acceler");
- TotalString = TotalString + title + '╢';
-
- title = Bundle.GetStringFromName("dapff.title-add-black-list");
- TotalString = TotalString + title + '╢';
- title = Bundle.GetStringFromName("dapff.text-add-black-list");
- TotalString = TotalString + title + '╢';
- title = Bundle.GetStringFromName("dapff.text-check-add-black-list");
- TotalString = TotalString + title + '╢';
- title = Bundle.GetStringFromName("dapff.button-yes");
- TotalString = TotalString + title +'╢';
- title = Bundle.GetStringFromName("dapff.button-no");
- TotalString = TotalString + title ;
-
- var obj = this.getDAPComponent();
- if( obj )
- obj.SetLocalizationString(TotalString);
-
- }
- catch( ex )
- {
- LOG(ex);
- }
- },
-
- };
-
-
- //=============================================================================
-
- var module =
- {
- _cid: Components.ID("{13AC88E5-B176-491a-8D8F-73473A0A57EF}"),
- _contractId: "@speedbit/dapcomponent-service;1",
- _name: "DAP Integration",
-
-
- _isRegistered: false,
-
- _factory: {
- _instance: null,
-
- createInstance: function(outer, iid)
- {
- LOG("createInstance");
- if (null != outer)
- {
- throw Components.results.NS_ERROR_NO_AGGREGATION;
- }
- if (null == this._instance)
- {
- this._instance = (new DAPService()).QueryInterface(iid);
- }
- return this._instance;
- }
- },
-
-
- //-------------------------------------------------------------------------
- registerSelf: function(compMgr, fileSpec, location, type)
- {
- if (this._isRegistered)
- {
- throw Components.results.NS_ERROR_FACTORY_REGISTER_AGAIN;
- }
-
- this._isRegistered = true;
-
- compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
- compMgr.registerFactoryLocation(this._cid, this._name, this._contractId,
- fileSpec, location, type);
- },
-
-
- //-------------------------------------------------------------------------
- getClassObject: function(compMgr, cid, iid)
- {
- if (!cid.equals(this._cid))
- {
- throw Components.results.NS_ERROR_NO_INTERFACE;
- }
-
- if (!iid.equals(Components.interfaces.nsIFactory))
- {
- throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
- }
- return this._factory;
- },
-
-
- //-------------------------------------------------------------------------
- canUnload: function(compMgr)
- {
- return true;
- },
- };
-
-
- function NSGetModule(compMgr, fileSpec)
- {
- LOG("NSGetModule");
- return module;
- }
-
- //=============================================================================
-